package com.villaday.idf.adapter3;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.model3.HotelRoomEntity;

import java.util.List;

public class FindHouseWindShopMoreAdapter extends AbsRecyclerViewAdapter<HotelRoomEntity.BodyBean.SalePlansBean> {

    OnItemPositionClickListener onPhotoClickListener;

    public FindHouseWindShopMoreAdapter(Context context) {
        super(context, com.villaday.idf.R.layout.recycle_fhwsd_item);
    }


    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, HotelRoomEntity.BodyBean.SalePlansBean d, final int position) {

        holder.bindTextViewWithHtml(R.id.tv_fi_money_left, "&yen;");

        List<String> descRules = d.getDescRules();
        String content = "";

        for (int i = 0; i < descRules.size(); i++) {
            if (i == descRules.size() - 1) {
                content = content + descRules.get(i) + "";
            } else {
                content = content + descRules.get(i) + "\n";
            }
        }

        holder.bindTextView(R.id.tv_fi_title, d.getName())
                .bindTextView(R.id.tv_fi_content, content);


        TextView textView = (TextView) holder.getView(R.id.tv_fi_confirm);
        textView.setTag(position);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onPhotoClickListener.onItemPositionClick(v, position);
            }
        });


        if (d.isVip()) {
            if (d.getBrokerageAmountValue() != null) {
                holder.getView(R.id.tv_fi_money_bt1).setVisibility(View.VISIBLE);
                holder.bindTextViewWithHtml(R.id.tv_fi_money_bt1, "立返 &yen;" + d.getBrokerageAmountValue());
            }

            if (d.getAddBrokerageAmountValue() != null && !d.getAddBrokerageAmountValue().equals("0")) {
                holder.getView(R.id.tv_fi_money_bt2).setVisibility(View.VISIBLE);
                holder.bindTextViewWithHtml(R.id.tv_fi_money_bt2, "加返 &yen;" + d.getAddBrokerageAmountValue());
            }else {
                holder.getView(R.id.tv_fi_money_bt2).setVisibility(View.GONE);
            }
        } else {
            holder.getView(R.id.tv_fi_money_bt1).setVisibility(View.GONE);
            holder.getView(R.id.tv_fi_money_bt2).setVisibility(View.GONE);
        }

        if (position == data.size() - 1) {
            holder.getView(R.id.vw_item_bottom).setVisibility(View.GONE);
        }

        if (d.isMorDay()) {
            holder.getView(R.id.tv_fi_money_left0).setVisibility(View.VISIBLE);
            holder.getView(R.id.tv_fi_money_right0).setVisibility(View.VISIBLE);
        } else {
            holder.getView(R.id.tv_fi_money_left0).setVisibility(View.GONE);
            holder.getView(R.id.tv_fi_money_right0).setVisibility(View.GONE);
        }
        holder.bindTextView(R.id.tv_fi_money, d.getAveragePriceValue());

        TextView tvTitle = (TextView) holder.getView(R.id.tv_fi_title);
        TextView tvContent = (TextView) holder.getView(R.id.tv_fi_content);
        TextView tvMoneyLeft = (TextView) holder.getView(R.id.tv_fi_money_left);
        TextView tvMoney = (TextView) holder.getView(R.id.tv_fi_money);
        TextView tvMoneyLeft0 = (TextView) holder.getView(R.id.tv_fi_money_left0);
        TextView tvMoneyRight0 = (TextView) holder.getView(R.id.tv_fi_money_right0);


        textView.setText("预订");
        if (d.isNotBooked()) {
            tvTitle.setTextColor(context.getResources().getColor(R.color.colorTextLight));
            tvContent.setTextColor(context.getResources().getColor(R.color.colorTextLight));
            tvMoney.setTextColor(context.getResources().getColor(R.color.colorTextLight));
            tvMoneyLeft0.setTextColor(context.getResources().getColor(R.color.colorTextLight));
            tvMoneyRight0.setTextColor(context.getResources().getColor(R.color.colorTextLight));

            tvMoneyLeft.setTextColor(context.getResources().getColor(R.color.colorTextLight));
            textView.setBackground(context.getResources().getDrawable(R.drawable.shape_solid_gray90));
            textView.setText(d.getNotBookedMsg() == null ? "预订" : d.getNotBookedMsg());
            textView.setEnabled(false);
        } else {
            tvTitle.setTextColor(context.getResources().getColor(R.color.colorTextBlack));
            tvContent.setTextColor(context.getResources().getColor(R.color.colorTextLight));
            tvMoney.setTextColor(context.getResources().getColor(R.color.colorF73637));
            tvMoneyLeft.setTextColor(context.getResources().getColor(R.color.colorF73637));
            tvMoneyLeft0.setTextColor(context.getResources().getColor(R.color.colorF73637));
            tvMoneyRight0.setTextColor(context.getResources().getColor(R.color.colorF73637));
            textView.setBackground(context.getResources().getDrawable(R.drawable.shape_fe_ff40));
            textView.setText("预订");
            textView.setEnabled(true);
        }
    }


    /**
     * Item点击监听 -- 添加头部后，头部的点击事件需自行处理
     */
    public void setOnEnergyItemClickListener(OnItemPositionClickListener onPhotoClickListener) {
        this.onPhotoClickListener = onPhotoClickListener;
    }


    public interface OnItemPositionClickListener {
        void onItemPositionClick(View view, int position);
    }
}
